package com.woniuxy.service.impl;

import com.woniuxy.entity.Appinfo;
import com.woniuxy.entity.Appointment;
import com.woniuxy.entity.AppointmentExample;
import com.woniuxy.mapper.AppinfoMapper;
import com.woniuxy.mapper.AppointmentMapper;
import com.woniuxy.service.AppointmentService;
import com.woniuxy.vo.AppointmentVO;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Service
public class AppointmentServiceImpl implements AppointmentService {
    @Resource
    private AppointmentMapper appointmentMapper;
    @Resource
    private AppinfoMapper appinfoMapper;
    @Override
    public List<AppointmentVO> selectCampOrderByStatus(Map<String,Object> map) throws Exception {
        return appointmentMapper.selectOrderByStatus(map);
    }

    @Override
    public int insertAppinfoReturnKey(Appinfo appinfo) throws Exception {
        return appinfoMapper.insertAppoinfoReturnKey(appinfo);
    }

    @Override
    public int insertAppointment(Appointment appointment) throws Exception {
        return appointmentMapper.insertSelective(appointment);
    }

    @Override
    public int updateAppointment(Appointment appointment) throws Exception {
        return appointmentMapper.updateByPrimaryKeySelective(appointment);
    }

    @Override
    public List<Appointment> selectAppointmentByCarId(Integer carId,Integer status,Integer userId) throws Exception {
        AppointmentExample example = new AppointmentExample();
        AppointmentExample.Criteria criteria = example.createCriteria();
        criteria.andCarIdEqualTo(carId);
//        criteria.andStatusEqualTo(status);
        criteria.andUserIdEqualTo(userId);
        List<Appointment> list = appointmentMapper.selectByExample(example);
        return list;
    }

    @Override
    public Appointment selectAppointmentByAppId(Integer appId) throws Exception {
        return appointmentMapper.selectByPrimaryKey(appId);
    }

    @Override
    public List<Appointment> selectAppointmentBycarIdAndStatus(Integer carId) throws Exception {
        return appointmentMapper.selectByStatusAndCarId(carId);
    }

    @Override
    public List<Appointment> selectAppointmentNotOver() throws Exception {
        return appointmentMapper.selectAppointmentNotOver();
    }
}
